package wps.util {
import mx.filters.BaseFilter;

import wps.component.IDrawingElement;
import wps.component.elementsetting.ISettingItem;

public class EnableChecker {

    //--------------------------------------------------------------------------
    //
    // Properties
    //
    //--------------------------------------------------------------------------

    private var _item:ISettingItem;

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * 需要检查的设置项目
     * @param item ISettingItem对象，用于对某个目标进行属性设置的控件
     */
    public function EnableChecker(item:ISettingItem) {
        _item = item;
    }

    //--------------------------------------------------------------------------
    //
    // Methods
    //
    //--------------------------------------------------------------------------

    /**
     * 根据目标是否支持对指定属性的设置，来判断该设置控件是否有效
     */
    public function getEnableValue():Boolean {
        var target:Object = _item.target;
        var targetProperty:String = _item.targetProperty;
        var targetStyle:String = _item.targetStyle;

        var enabled:Boolean;

        if (target is IDrawingElement) {
            var de:IDrawingElement = target as IDrawingElement;

            var checkCondition:String = targetProperty ? targetProperty : targetStyle ? targetStyle : null;
            enabled = de.excludedSetting.indexOf(checkCondition) < 0;

        } else if (target is BaseFilter) {
            // 目标是filter类型的对象时，如果filter包含指定属性，表示可以对filter进行设置
            enabled = target.hasOwnProperty(targetProperty);
        } else {
            enabled = target ? true : false;
        }

        return enabled;
    }

}

}
